import axios from 'axios'
import { ElNotification } from 'element-plus'
const REQUEST_BASE_URL = import.meta.env.VITE_REQUEST_BASE_URL

// 创建axios实例
const service = axios.create({
  baseURL: REQUEST_BASE_URL,
  timeout: 10000,
})
const NotificationFn = (message: string) => {
  ElNotification({ message, type: 'error' })
}
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    const message = error.response.data.message || '请求异常'
    NotificationFn(message)
    return Promise.reject(error)
  },
)
export default service
